﻿using System.Collections;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SiteFox.WebParts.Multimedia
{
    [AspNetHostingPermission(SecurityAction.Demand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand,
      Level = AspNetHostingPermissionLevel.Minimal)]
    
    public class VideoPlayerWP : WebPart
    {
        Literal _lit_Object;

        private string _VideoUrl = "";
        [Personalizable(true)]
        [WebBrowsable(true)]
        [WebDescription("Enter video file url.")]
        [WebDisplayName("VideoUrl")]
        public string VideoUrl
        {
            get { return _VideoUrl; }
            set { _VideoUrl = value; }
        }

        private int _VideoWidth;
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("Width (px).")]
        [WebDisplayName("Width (px)")]
        public int VideoWidth
        {
            get { return _VideoWidth; }
            set { _VideoWidth = value; }
        }

        private int _VideoHeight;
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("Height (px).")]
        [WebDisplayName("Height (px)")]
        public int VideoHeight
        {
            get { return _VideoHeight; }
            set { _VideoHeight = value; }
        }

        private bool _AllowFullScreen = false;
        [Personalizable()]
        [WebBrowsable(true)]
        [WebDescription("Allow FullScreen")]
        [WebDisplayName("Allow FullScreen")]
        public bool AllowFullScreen
        {
            get { return _AllowFullScreen; }
            set { _AllowFullScreen = value; }
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();
            string _AppPath = HttpContext.Current.Request.ApplicationPath;
            if (_AppPath == "/")
            {
                _AppPath = "";
            }
            _lit_Object = new Literal();
            _lit_Object.Text =  "<object id=\"" + this.ID + "_player\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + _VideoWidth + "\" height=\"" + _VideoHeight + "\">" +
	                                "<param name=\"movie\" value=\"" + _AppPath + "/Common/swf/flowplayer-3.2.5.swf\" />" +
                                    "<param name=\"flashvars\" value='config={\"clip\":\"" + _VideoUrl + "\"}' />" +
                                    "<param name=\"allowfullscreen\" value=\"" + _AllowFullScreen.ToString() + "\" />" +
                                    "<embed type=\"application/x-shockwave-flash\" width=\"" + _VideoWidth + "\" height=\"" + _VideoHeight + "\" src=\"" + _AppPath + "/Common/swf/flowplayer-3.2.5.swf\" flashvars='config={\"clip\":\"" + _VideoUrl + "\"}' allowfullscreen=\"" + _AllowFullScreen.ToString() + "\" />" +
	                            "</object>";
            Controls.Add(_lit_Object);
        }
    }
}
